import axios from "axios";
import { ElMessageBox } from "element-plus";
const isNewVersion = () => {
  const hostUrl = window.location.origin;
  const url = `${hostUrl}/version.json?t=${new Date().getTime()}`;
  axios.get(url).then((res) => {
    console.log(res);
    
    if (res.status === 200) {
      const vueVersion = res.data.version;
      const localVueVersion = localStorage.getItem("vueVersion");
      if (localVueVersion && localVueVersion !== vueVersion) {
        localStorage.setItem("vueVersion", vueVersion);
        ElMessageBox.alert("版本升级，正常使用需要刷新系统！", "提示", {
          confirmButtonText: "确定",
          showClose: false,
          type: "warning",
          callback: () => {
            location.reload();
          },
        });
        return;
      } else {
        localStorage.setItem("vueVersion", vueVersion);
      }
    }
  });
};

export default {
  isNewVersion,
};
